<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="model.*"%>
<%@ page import="dao.*"%>
<%@ page import="java.util.*"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	request.setCharacterEncoding("utf-8");
	response.setCharacterEncoding("utf-8");
	String user = (String)session.getAttribute("user");
	if(user!=null && user.equals("1")){
		
	}else {
		response.sendRedirect("Login.jsp");
	}
%>
<%
	List<View> views = new ArrayList<View>();
	views = ViewDao.getViews();
	for (View item : views) {
		System.out.println(item.getName());
	}
	request.setAttribute("views", views);
%>
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8" />
<title>管理旅游景点</title>


<jsp:include page="Header.jsp" flush="true"></jsp:include>


<!-- Latest Products -->
<div id="旅游景点">
	<div class="content-lg container">
		<div class="row margin-b-40">
			<div class="col-sm-6">
				<h2>管理旅游景点</h2>
				<p></p>
			</div>
		</div>
		<!--// end row -->

		<div class="row">
			<h3>
				<a href="<%=request.getContextPath()%>/admin/AddView.jsp">添加景点</a>
			</h3>
			<table class="table table-bordered mtable2" width="100%"
				cellspacing="0">
				<thead>
					<tr>
						<th>序号</th>
						<th>名称</th>
						<th>图片</th>
						<th>信息</th>
						<th>价格</th>
						<th>操作</th>
					</tr>
				</thead>
			
				<tbody>
					<c:forEach var="view" items="${views}" varStatus="status">
						<tr>
							<td>${status.index +1}</td>
							<td>${view.vcname }</td>
							<td><a target="_blank"
								href="<%=request.getContextPath()%>/${view.location }">查看图片</a></td>
							<td>${view.info }</td>
							<td>${view.price }</td>
							<td><a
								href="javascript:if(confirm('确定要修改吗?'))location='<%=request.getContextPath()%>/admin/UpdateView.jsp?vname=${view.name }'">修改</a>
								<a
								href="javascript:if(confirm('确定要删除吗?'))location='<%=request.getContextPath()%>/ViewServlet?vname=${view.name }&handle=delView'">删除</a>
							</td>

						</tr>

					</c:forEach>
				</tbody>
			</table>

		</div>
		<!--// end row -->
	</div>
</div>
<!-- End Latest Products -->

<jsp:include page="Footer.jsp" flush="true"></jsp:include>
<%
	String flag = "";
	String scerror = "";
	flag = (String) request.getAttribute("flag");
	System.out.println("jspflag" + flag);
	if (flag != null) {
		if (flag.equals("1")) {
			scerror = "删除成功。";
			out.print("<script language='javascript'>alert('" + scerror + "');</script>");
		}
		if (flag.equals("0")) {
			scerror = "删除失败。";
			out.print("<script language='javascript'>alert('" + scerror + "');</script>");
		}
		if (flag.equals("3")) {
			scerror = "添加成功。";
			out.print("<script language='javascript'>alert('" + scerror + "');</script>");
		}
		if (flag.equals("2")) {
			scerror = "添加失败。";
			out.print("<script language='javascript'>alert('" + scerror + "');</script>");
		}
		if (flag.equals("5")) {
			scerror = "修改成功。";
			out.print("<script language='javascript'>alert('" + scerror + "');</script>");
		}
		if (flag.equals("4")) {
			scerror = "修改失败。";
			out.print("<script language='javascript'>alert('" + scerror + "');</script>");
		}

	}
	System.out.println(scerror);
%>
<!-- Back To Top -->
<a href="javascript:void(0);" class="js-back-to-top back-to-top">Top</a>

<!-- JAVASCRIPTS(Load javascripts at bottom, this will reduce page load time) -->
<!-- CORE PLUGINS -->
<script src="vendor/jquery.min.js" type="text/javascript"></script>
<script src="vendor/jquery-migrate.min.js" type="text/javascript"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js"
	type="text/javascript"></script>
</body>
<!-- END BODY -->
</html>